﻿using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web.Mvc;
using Nop.Core.Domain.Directory;
using Nop.Plugin.Remote.Vishnu.Domain;
using Nop.Plugin.Remote.Vishnu.Models;
using Nop.Plugin.Remote.Vishnu.Services;
using Nop.Services.Configuration;
using Nop.Services.Directory;
using Nop.Services.Shipping;
using Nop.Web.Framework.Controllers;
using Telerik.Web.Mvc;
using Nop.Services.Localization;
using Nop.Core;

namespace Nop.Plugin.Remote.Vishnu.Controllers
{
    [AdminAuthorize]
    public class VishnuController : Controller
    {
        private readonly ILocalizationService _localizationService;
        private readonly IWebHelper _webHelper;
        private readonly VishnuSettings _vishnuSettings;
        private readonly ISettingService _settingService;

        public VishnuController(
            ILocalizationService localizationService,
            IWebHelper webHelper,
            VishnuSettings vishnuSettings, ISettingService settingService)
        {
            this._localizationService = localizationService;
            this._webHelper = webHelper;
            this._vishnuSettings = vishnuSettings;
            this._settingService = settingService;
        }

        public ActionResult Configure()
        {
            var model = new VishnuModel();
            model.SSLMandatory = _vishnuSettings.SSLMandatory;
            model.StoreColor = _vishnuSettings.HtmlColor;

            return View("Nop.Plugin.Remote.Vishnu.Views.Vishnu.Configure", model);
        }

        [HttpPost]
        [FormValueRequired("save")]
        public ActionResult Configure(VishnuModel model)
        {
            if (!ModelState.IsValid)
            {
                return Configure();
            }

            //save settings
            _vishnuSettings.SSLMandatory = model.SSLMandatory;
            _vishnuSettings.HtmlColor = model.StoreColor;
            _settingService.SaveSetting(_vishnuSettings);

      
            return View("Nop.Plugin.Remote.Vishnu.Views.Vishnu.Configure", model);
        }


    }
}
